﻿
@{
    ViewBag.Title = "OrderAudit";
    Layout = "~/Views/Shared/_Layout.cshtml";
}


@section style{
    <style>
        .form-horizontal .control-label {
            width: 20%;
            float: left;
            text-align: right;
        }

        .col-sm-3 {
            width: 80%;
            float: left;
        }
    </style>
    <link href="@Url.Content("~/css/plat/blue.css")" rel="stylesheet">
}
<form id="form1" class="form-horizontal">
    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="box-body">
                    <div class="form-group" id="divAuditResult">
                        <label class="col-sm-2 control-label" for="name">审核结果：</label>
                        <div class="col-sm-3">
                            <label class="radio-inline">
                                <input type="radio" value="1" name="rdAuditResult" checked="checked">通过
                            </label>
                            <label class="radio-inline">
                                <input type="radio" value="2" name="rdAuditResult">驳回
                            </label>
                        </div>
                    </div>
                    <div class="form-group" style="display:none;" id="divReject">
                        <label class="col-sm-2 control-label" for="name">驳回原因：</label>
                        <div class="col-sm-3">
                            <select class="form-control" style="width:300px;" name="selReject" id="selReject"></select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="name">备注：</label>
                        <div class="col-sm-3">
                            <textarea name="txtRemark" rows="2" cols="20" id="txtRemark" class="form-control" style="width:300px;"></textarea>
                        </div>
                    </div>
                </div>
                <div class="box-footer text-center">
                    <button class="btn btn-primary" type="button" id="btnSave">确 定 </button>
                    <button class="btn" type="button" id="cancel">取 消 </button>
                    <input type="hidden" id="hidOrderId" name="hidOrderId" value="@ViewBag.OrderId" />
                </div>
            </div>

        </div>
        <!-- /.row -->
    </section>

</form>
@section scriptsBottom{
    <script src="@Url.Content("~/js/icheck.min.js")"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('input').iCheck({
                radioClass: 'iradio_flat-blue'
            });

            $("#btnSave").click(function () {
                save();
            });
            $("#cancel").click(function () {
                BMCW.closeTopLayer();
            });

            $("input:radio[name='rdAuditResult']").on('ifChecked', function (event) {
                if ($(this).val() == 2) {
                    $("#divReject").show();
                } else {
                    $("#divReject").hide();
                }
            });
            initRejectContent();
            initFormValidate();
        });

       //驳回原因
        function initRejectContent() {
           var url = '@Url.Action("GetRejectDicByBizId", "Order")?bizId=@ViewBag.BizTypeId';
            $("#selReject").append("<option value=''>请选择驳回原因</option>");
            
           BMCW.ajax({
               url: url,
               type: "GET",
               success: function (o) {
                   if (o.status == 0) {
                       $.each(o.data, function (i) {
                           $("#selReject").append("<option value='" + o.data[i].RejectContent + "'>" + o.data[i].RejectContent + "</option>");
                       });
                       $("#selReject").append("<option value='其它'>其它</option>");
                   }
               }
           });
       }

        //保存
        function save() {
            var bootstrapValidator = $("#form1").data('bootstrapValidator');
            bootstrapValidator.validate();

            if (bootstrapValidator.isValid()) {
                var url = '@Url.Action("SaveAudit", "Order")';
                var arrData = $("#form1").serializeArray();
                var data = {};
                for (var i = 0; i < arrData.length; i++) {
                    data[arrData[i].name] = arrData[i].value;
                }
                BMCW.ajax({
                    url: url,
                    type: "POST",
                    data: data,
                    success: function (o) {
                        if (o.status == 0) {
                            BMCW.msg("保存成功", function () {
                                BMCW.getTopSelectedWin().initData();
                            });
                        } else {
                            BMCW.alert("保存失败");
                        }
                    }
                });
            }
        }

        
        //验证
        function initFormValidate() {
            $("#form1").bootstrapValidator({
                submitHandler: function (valiadtor, loginForm, submitButton) {
                    valiadtor.defaultSubmit();
                },
                fields: {
                    rdAuditResult: {
                        validators: {
                            notEmpty: {
                                message: '审核结果不能为空'
                            }
                        }
                    },
                    selReject: {
                        validators: {
                            callback: {
                                message: '驳回原因不能为空',
                                callback: function (value, validator) {
                                    if ($("input:radio[name='rdAuditResult']:checked").val() == 2 && value == "") {
                                        return false;
                                    } else {
                                        return true;
                                    }
                                }
                            }
                        }
                    },
                    txtRemark: {
                        validators: {
                            stringLength: {
                                /*长度提示*/
                                min: 0,
                                max: 500,
                                message: '备注长度必须在1到500之间'
                            }
                        }
                    }
                }
            });
        }

    </script>
}

